<?php
class eventdao extends daobase {
	 /**
	  * getEvents
	  */
	 public function getEvents($userId){
	 	$events = array();
	 	$sql = "select * from events where creatorId='$userId' order by id desc";
	 	$creator = $this->fetchit($sql);
	 	$userIdChange = $userId.";";
	 	$sql = "select * from events where partorIds like '%$userIdChange%'  order by id desc";
	 	$partor = $this->fetchit($sql);
	 	$events[0] = $creator;
	 	$events[1] = $partor;
	 	return $events;
	 }
	 /**
	  * create new event
	  *
	  * @param unknown_type $name
	  * @param unknown_type $des
	  * @param unknown_type $start
	  * @param unknown_type $end
	  */
	 public function createEvent($name,$des,$start,$end,$userId,$createD){
	 	$sql = "insert into events(name,description,startDate,endDate,creatorId,createDate)
	 	 values ('$name','$des','$start','$end','$userId','$createD')";
	 	$create = $this->queryit($sql);
	 	if ($create){
	 		$sql = "select id from events where name= '$name' and creatorId='$userId' and createDate ='$createD'";
	 		$newE = $this->fetchit($sql);
	 		return $newE[0][0];
	 	}
	 	return false;
	 }
	 
	 public function addFile($name,$targetFile,$postFolder){
	 	$sql = "insert into files(name,parth,folderId) values('$name','$targetFile','$postFolder')";
	 	$add = $this->queryit($sql);
	 	return $add;
	 }
	 
	 public function getRootEventDir($event){
	 	$sql = "select fileFolder from events where id= '$event'";
	 	$root = $this->fetchit($sql);
	 	return $root[0][0];
	 }
	 
	 public function updateRootEventDir($event){
	 	$sql ="update events set fileFolder='$event' where id='$event'";
	 	$query = $this->queryit($sql);
	 	return $query;
	 }
	 
	 public function getTargetEventInfo($eventId){
	 	$sql = "select * from events where id='$eventId'";
	 	$eventInfo = $this->fetchit($sql);
	 	return $eventInfo;
	 }
	 public function getEventId($createD,$userId){
	 	$sql = "select id from events where createDate='$createD' and creatorId ='$userId'";
	 	$eventId = $this->fetchit($sql);
	 	return $eventId[0][0];
	 }
	 public function deleteEvent($eventID){
	 	$sql = "delete from files where folderId ='$eventID'";
	 	$delete = $this->queryit($sql);
	 	$sql = "delete from events where id ='$eventID'";
	 	$delete = $this->queryit($sql);
	 	return $delete;
	 }
	 public function getFileByDbFolder($folderId){
	 	$sql = "select * from files where folderId='$folderId' order by id desc";
	 	$files = $this->fetchit($sql);
	 	return $files;
	 }
	 public function deleteFileByParth($parth){
	 	$sql ="delete from files where parth='$parth'";
	 	$delete = $this->queryit($sql);
	 	return $delete;
	 }
}